User guide previous pagenext page

2.2: Axes inside layouts Go back up one level

(The code for this example can be found here: [ view | edit | run ] )

When using layouts to position axes, the position property is set by the layout, not the user. Whether the Position or OuterPosition property is used is determined by the ActivePositionProperty property of the axes. Note that the default setting is "outerposition".

The following example illustrates the two usages.

Open a window

Open a new figure window and remove the toolbar and menus.

window = figure( 'Name', 'Axes inside layouts', ...
            'MenuBar', 'none', ...
            'Toolbar', 'none', ...
            'NumberTitle', 'off' );

Create the layout

The layout involves two axes side by side. This is done using a flexible horizontal box. The left-hand axes is left with the ActivePositionProperty set to "outerposition", but the right-hand axes is switched to use Position.

hbox = uix.HBoxFlex('Parent', window, 'Spacing', 3);
axes1 = axes( 'Parent', hbox, ...
    'ActivePositionProperty', 'outerposition' );
axes2 = axes( 'Parent', hbox, ...
    'ActivePositionProperty', 'Position' );
set( hbox, 'Widths', [-2 -1] );

Fill the axes

Using OuterPosition (left-hand axes) is the normal mode and looks good for virtually any plot type. Using Position is only really useful for 2D plots with the axes turned off, such as images.

x = membrane( 1, 15 );
surf( axes1, x );
lighting( axes1, 'gouraud' );
shading( axes1, 'interp' );
l = light( 'Parent', axes1 );
camlight( l, 'head' );
axis( axes1, 'tight' );

imagesc( x, 'Parent', axes2 );
set( axes2, 'xticklabel', [], 'yticklabel', [] );


© 2016 The MathWorks Ltd Terms of Use Patents Trademarks